home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / qtsimpleapplet / src / qtsimpleapplet.java
Encoding:
Java Source  |  2000-06-23  |  2.1 KB  |  73 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.applet.Applet;
  9. import java.awt.*;
  10. import java.io.*;
  11.  
  12. import quicktime.*;
  13. import quicktime.io.QTFile;
  14.  
  15. import quicktime.app.QTFactory;
  16. import quicktime.app.display.*;
  17. import quicktime.app.image.ImageDrawer;    // for exceptions
  18.  
  19. public class QTSimpleApplet extends Applet {
  20.     private Drawable myQTContent;
  21.     private QTCanvas myQTCanvas;
  22.     
  23.     public void init () {
  24.         try {
  25.             // this is a workaround required by a bug in the loading
  26.             // mechanism of applets using the JavaPlugin on Netscape on Win
  27.             if (QTSession.isInitialized() == false)
  28.                 QTSession.open();
  29.  
  30.                 // set up a QTCanvas which will disply its content 
  31.                 // at its original size of smaller and centered in the space given
  32.                 // to the QTCanvas when the applet is layed out
  33.             setLayout (new BorderLayout());
  34.             myQTCanvas = new QTCanvas (QTCanvas.kInitialSize, 0.5F, 0.5F);
  35.             add (myQTCanvas, "Center");        
  36.             
  37.             QTFile file = new QTFile (getCodeBase().getFile() + getParameter("file"));
  38.             myQTContent = QTFactory.makeDrawable (file);
  39.         } catch (QTException qtE) {
  40.                 // something wrong with the content but QT itself is OK
  41.             if (QTSession.isInitialized())
  42.                 myQTContent = ImageDrawer.getQTLogo();
  43.             else
  44.                 throw new RuntimeException (qtE.getMessage());        
  45.         } catch (FileNotFoundException fnfE) {
  46.             myQTContent = ImageDrawer.getQTLogo();
  47.         
  48.         } catch (IOException ioE) {
  49.                 // the IOException would occur as a violation of
  50.                 // java security settings on the user machine - throw it again
  51.             throw new SecurityException (ioE.getMessage());
  52.         }
  53.     }    
  54.  
  55.     public void start () { 
  56.         try { // if QT was not successfully initialized the QTCanvas will be null
  57.             if (myQTCanvas != null)
  58.                 myQTCanvas.setClient (myQTContent, true);            
  59.         } catch (QTException e) {
  60.             e.printStackTrace();
  61.         }
  62.     }
  63.     
  64.     public void stop () { 
  65.         if (myQTCanvas != null)
  66.             myQTCanvas.removeClient();
  67.     }
  68.     
  69.     public void destroy () {
  70.         QTSession.close();
  71.     }
  72. }
  73.